#pragma once

#include <d3dx9math.h>
#include "Vector.h"

class Plane : public D3DXPLANE
{
public:
	inline void Normalize()
	{
		float mag;
		mag = sqrt(a*a + b*b + c*c);
		a = a / mag;
		b = b / mag;
		c = c / mag;
		d = d / mag;
	}
	
	// Normal faces away from you if you send in verts
	// in counter clockwise order...
	inline void Init(const Vector3& p0, const Vector3& p1, const Vector3& p2)
	{
		D3DXPlaneFromPoints(this, &p0, &p1, &p2);
		Normalize();
	}
	
	
	inline bool Inside(const Vector3& point, const float radius) const
	{
		float fDistance; // Calculate our distances to each of the planes

		// Find the distance to this plane
		fDistance = D3DXPlaneDotCoord(this, &point);

		// If this distance is < -radius, we are outside
		return (fDistance >= -radius);
	}

	inline bool Inside(const Vector3& point) const
	{
		// Inside the plane is defined as the direction the normal is facing
		float result = D3DXPlaneDotCoord(this, &point);
		return (result >= 0.f);
	}
};